package com.example.administrator.nurse.feature;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.base.BaseFragment;
import com.example.administrator.nurse.common;
import com.example.administrator.nurse.fragment.FeatureDataFragment;
import com.example.administrator.nurse.fragment.FeatureRecodeFragment;
import com.example.administrator.nurse.util.imageLoderHelper;
import com.example.administrator.nurse.widget.CommonViewPagerHelper;
import com.example.administrator.nurse.widget.PagerAdapter;
import com.example.administrator.nurse.widget.PagerSelectedListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/31.
 *
 */

public class FeatureActivity extends BaseActivity {

    private ImageView feature_tab;
    private int tabWidth;
    private List<BaseFragment> fragmentArr;
    private String[] tagArr={"recode","data"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();

    }

    @Override
    protected int setLayotId() {
        return R.layout.feature_main;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }

    private void initView(){

        /** 扫码 */
       /* f(R.id.scan).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                common.jumpToCoder(FeatureActivity.this,null);

            }
        });*/

        feature_tab= (ImageView) f(R.id.feature_tab);
        tabWidth=getResources().getDrawable(R.drawable.feature_tab).getIntrinsicWidth();
        fragmentArr=new ArrayList<BaseFragment>();

        fragmentArr.add(new FeatureRecodeFragment());
        fragmentArr.add(new FeatureDataFragment());

        ViewPager viewPager= (ViewPager) findViewById(R.id.fragment_container);
        viewPager.setAdapter(new PagerAdapter<BaseFragment>(getSupportFragmentManager(), fragmentArr));


      CommonViewPagerHelper helper=new CommonViewPagerHelper((ViewPager) findViewById(R.id.fragment_container));
        helper.withAdapter(new PagerAdapter<BaseFragment>(getSupportFragmentManager(),fragmentArr))
                .withListLength(fragmentArr.size())
                .withOnPageChangeListener(new PagerSelectedListener(0, tabWidth, feature_tab));
        helper.initHelper();
        try {
            helper.setListItemClick(findViewById(R.id.feature_txt),findViewById(R.id.feature_search));
        } catch (CommonViewPagerHelper.ListItemNumberOutofList listItemNumberOutofList) {
            listItemNumberOutofList.printStackTrace();
        }

        findViewById(R.id.back_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

   @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode){
            case common.CodeScan:
               // Log.d("zzzzz","data "+data.getStringExtra("content"));
                break;
            /** 个人信息页面返回 */
        }
    }

}
